package com.jdk.demo.thread.countDownLatch;

import java.util.concurrent.CountDownLatch;

public class Test {

	public static void main(String[] args) {
		CountDownLatch begin = new CountDownLatch(2);

		Thread thread = new Thread(() -> {
			try {
				System.out.println("the t1 start");
				begin.await();
				System.out.println("the t1 end");
			} catch (Exception e) {
				e.printStackTrace();
			}
		});
		thread.start();
		
		Thread thread2 = new Thread(() -> {
			try {
				System.out.println("the t2 start");
				begin.await();
				System.out.println("the t2 end");
			} catch (Exception e) {
				e.printStackTrace();
			}
		});
		thread2.start();

		try {
			begin.countDown();
			Thread.sleep(2000);
			begin.countDown();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
